//package com.quan.config;
//
//import com.alibaba.druid.filter.Filter;
//import com.alibaba.druid.filter.stat.StatFilter;
//import com.alibaba.druid.pool.DruidDataSource;
//import com.google.common.collect.Lists;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//
//@Configuration
////扫描 Mapper 接口并容器管理
//@MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory")
//public class MasterDataSourceConfig {
//
//    // 精确到 master 目录，以便跟其他数据源隔离
//    static final String PACKAGE = "com.ljtao.dtxmqtxbank1.dao";
//    static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
//    static final String TYPE_ALIASES_PACKAGE="com.ljtao.dtxmqtxbank1.entity";
//
//    @Value("${master.datasource.url}")
//    private String url;
//
//    @Value("${master.datasource.username}")
//    private String user;
//
//    @Value("${master.datasource.password}")
//    private String password;
//
//    @Value("${master.datasource.driverClassName}")
//    private String driverClass;
//
//    @Bean(name = "masterDataSource")
//    @Primary
//    public DataSource masterDataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setDriverClassName(driverClass);
//        dataSource.setUrl(url);
//        dataSource.setUsername(user);
//        dataSource.setPassword(password);
//        dataSource.setProxyFilters(Lists.newArrayList(statFilter()));
//        return dataSource;
//    }
//    @Bean
//    public Filter statFilter(){
//        StatFilter statFilter=new StatFilter();
//        statFilter.setSlowSqlMillis(1);
//        //statFilter.setLogSlowSql(true);
//        statFilter.setMergeSql(true);
//        return statFilter;
//    }
//    @Bean(name = "masterTransactionManager")
//    @Primary
//    public DataSourceTransactionManager masterTransactionManager() {
//        return new DataSourceTransactionManager(masterDataSource());
//    }
//
//    @Bean(name = "masterSqlSessionFactory")
//    @Primary
//    public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)
//            throws Exception {
//        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//        sessionFactory.setDataSource(masterDataSource);
//        ////这里注意, 设置该参数时打成jar启动会找不到该包下的类,目前未找到解决方案。（mybatis-spring-boot-starter把这个版本换成2.1.0）
//        sessionFactory.setTypeAliasesPackage(MasterDataSourceConfig.TYPE_ALIASES_PACKAGE);
//        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MasterDataSourceConfig.MAPPER_LOCATION));
//
//        return sessionFactory.getObject();
//    }
//}